<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('隐患饼状图/类型')" />
</head>

<body>
<input id="data" type="hidden" th:value="${data}"/>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="width: 100%;height:400px;"></div>
</body>
<th:block th:include="include :: footer" />
<script src="/libs/echarts/echarts.min.js"></script>
<script type="text/javascript">
    var data = $("#data").val();
    var legend_data = [];
    var series_data = data.replace(/key/g, "name").replace(/values/g,"value");
    data = JSON.parse(data);
    for(var i in data){
        legend_data.push(data[i].key);
    }
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
    option = {
        title : {
            text: '隐患饼状图/隐患类型',
            subtext: '实时数据',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: legend_data
        },
        series : [
            {
                name: '隐患类型',
                type: 'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data: JSON.parse(series_data),
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>
</html>